import {Component, OnInit} from '@angular/core';
import {TypeService} from '../../../shared/service/type.service';
import {ActivatedRoute} from '@angular/router';
import {HttpParams} from '@angular/common/http';

@Component({
  selector: 'app-type-article',
  templateUrl: './type-article.component.html',
  styleUrls: ['./type-article.component.scss']
})
export class TypeArticleComponent implements OnInit {
  name;
  nums;
  articles;

  constructor(private typeService: TypeService, private router: ActivatedRoute) {
  }

  ngOnInit() {
    this.router.queryParams.subscribe((param) => {
      this.name = param.name;
      this.nums = param.nums;
      const params = new HttpParams().set('type', this.name);
      this.typeService.getArticlesByType(params).subscribe((res) => {
        this.articles = res;
      });
    });
  }

}
